home *** CD-ROM | disk | FTP | other *** search
- {*****************************************************************************
- This program patches TPC.EXE, version 5.0. The resulting command line
- compiler can produce additional code to call a user-supplied routine whenever
- a pointer is dereferenced. The user-supplied routine can perform any of a
- variety of operations: error-checking the pointer, transparently supporting
- handle-based pointers for heap compaction, or implementing a complete virtual
- heap in EMS or on disk.
-
- To use this program, compile it and run it from a directory where a copy of
- TPC.EXE resides. The program directly changes TPC.EXE -- no backup is made.
- The program works only on version 5.00 of Turbo Pascal, which to our
- knowledge is the only released version of Turbo 5. We have not developed a
- similar patch for TURBO.EXE -- that would be possible, but the integrated
- compiler is linked differently, making it a chore to find the patch
- locations.
-
- If the patching program halts with an error, be sure to restore a fresh copy
- of TPC.EXE from a backup. At the time of the error, the compiler may be
- partially patched.
-
- For further information on using the patched compiler, refer to HEAP.DOC.
-
- Written 3/8/89, Kim Kokkonen, TurboPower Software.
- Compuserve ID 72457,2131
- Copyright (C) TurboPower Software, 1989. All rights reserved.
- May be distributed freely, but not commercially without express permission
- of TurboPower Software.
-
- Version 1.0
- First release.
- Version 5.0
- Updated for Turbo Pascal 5.0.
- *****************************************************************************}
-
- {$R-,S-,I+,F-,B-,V-}
-
- program HeapPatch;
-
- const
- DerefInterrupt = $66; {Change this constant to use a different
- interrupt number to call the user routine}
-
- var
- f : file of Byte;
-
- procedure Abort;
- begin
- WriteLn('Cannot complete patch. Be sure to restore a clean copy of TPC.EXE');
- Halt(1);
- end;
-
- procedure P(loc : LongInt; o, n : Byte);
- var
- b : Byte;
- begin
- Seek(f, loc);
- Read(f, b);
- if b <> o then begin
- WriteLn('At address ',loc, ' expected data:', o, ' but found:', b);
- Abort;
- end;
- Seek(f, loc);
- Write(f, n);
- end;
-
- begin
- Assign(f, 'TPC.EXE');
- Reset(f);
- if FileSize(f) <> 56925 then begin
- WriteLn('Unknown version of TPC.EXE');
- Abort;
- end;
-
- {Patch to support pointer checking}
- P($0000046D,$4D,$50); {Allow /$P+ on command line}
- P($00000470,$E8,$BA); {...at expense of /$M}
- P($00000471,$53,$08);
- P($00000473,$72,$EB);
- P($00000474,$33,$D9);
-
- P($00000898,$BF,$C3); {Disable TPC patch checker}
-
- P($000008F6,$90,$00); {Expanded copy of switch_dir_table}
- P($000008F8,$90,$40);
- P($000008F9,$90,$00);
- P($000008FA,$90,$00);
- P($000008FB,$90,$81);
- P($000008FC,$90,$00);
- P($000008FD,$90,$00);
- P($000008FE,$90,$00);
- P($000008FF,$90,$84);
- P($00000900,$90,$00);
- P($00000901,$90,$00);
- P($00000902,$90,$00);
- P($00000903,$90,$00);
- P($00000904,$90,$20);
- P($00000905,$90,$00);
- P($00000906,$90,$01);
- P($00000907,$90,$00);
- P($00000908,$90,$00);
- P($00000909,$90,$00);
- P($0000090A,$90,$00);
- P($0000090B,$90,$00);
- P($0000090C,$90,$00);
- P($0000090D,$90,$00);
- P($0000090E,$90,$00);
- P($0000090F,$90,$82);
- P($00000910,$90,$00);
- P($00000911,$90,$00);
- P($00000912,$90,$80);
- P($00000913,$90,$80);
- P($00000914,$90,$00);
- P($00000915,$90,$88);
- P($00000916,$90,$02);
- P($00000917,$90,$00);
- P($00000918,$90,$04);
- P($00000919,$90,$00);
- P($0000091A,$90,$00);
- P($0000091B,$90,$00);
- P($0000091C,$90,$10);
- P($0000091D,$90,$00);
- P($0000091E,$90,$08);
- P($0000091F,$90,$00);
- P($00000920,$90,$F7);
- P($00000921,$90,$06);
- P($00000922,$90,$20);
- P($00000923,$90,$19);
- P($00000924,$90,$08); {New option mask for $P directive}
- P($00000925,$90,$00);
-
- P($00000926,$90,$74); {Generate DerefInterrupt code}
- P($00000927,$90,$06);
- P($00000928,$90,$B8);
- P($00000929,$90,$CD);
- P($0000092A,$90,DerefInterrupt);
- P($0000092B,$90,$E8);
- P($0000092C,$90,$F6);
- P($0000092D,$90,$6B);
- P($0000092E,$90,$E9);
- P($0000092F,$90,$A9);
- P($00000930,$90,$6B);
-
- P($000044E4,$F4,$3A); {Jump to DerefInterrupt generator}
- P($000044E5,$2F,$C4);
-
- P($00008C95,$81,$F6); {Refer to relocated switch_dir_table}
- P($00008C96,$8E,$06);
-
- P($00008D89,$81,$F6); {Refer to relocated switch_dir_table}
- P($00008D8A,$8E,$06);
-
- P($00009080,$00,$01); {Add $P as an acceptable switch directive}
- P($00009081,$00,$50);
- P($00009082,$90,$00);
-
- P($0000C9E9,$20,$50); {Modify compiler version number}
-
- Close(f);
- WriteLn('TPC.EXE 5.0 patched for pointer-dereference interrupts');
- end.